package com.doubao.common.mq.producer;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@RequiredArgsConstructor
public class NotificationProducer {

    private final MessageProducer messageProducer;

    private static final String TOPIC = "doubao-notification";

    /**
     * 发送通知消息
     */
    public void sendNotification(String userId, String title, String content, String type) {
        Map<String, Object> message = new HashMap<>();
        message.put("userId", userId);
        message.put("title", title);
        message.put("content", content);
        message.put("type", type);
        message.put("timestamp", System.currentTimeMillis());

        messageProducer.sendMessage(TOPIC, message);
    }

    /**
     * 发送延迟通知消息
     * @param delayLevel 延迟等级：1=1s, 2=5s, 3=10s, 4=30s, 5=1m, 6=2m, 7=3m, 8=4m, 9=5m, 10=6m, 11=7m, 12=8m, 13=9m, 14=10m, 15=20m, 16=30m, 17=1h, 18=2h
     */
    public void sendDelayedNotification(String userId, String title, String content,
                                        String type, int delayLevel) {
        Map<String, Object> message = new HashMap<>();
        message.put("userId", userId);
        message.put("title", title);
        message.put("content", content);
        message.put("type", type);
        message.put("timestamp", System.currentTimeMillis());

        messageProducer.sendDelayedMessage(TOPIC, message, delayLevel);
    }
}